package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.pojo.*;

import com.itheima.service.OrderService;
import com.itheima.service.OrderSettingService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ordersettinglist")
public class OrderSettingListController {
    @Reference
    private OrderSettingService orderSettingService;
    @Reference
    private OrderService orderService;

    @RequestMapping("/mobileAdd")
    public Result mobileAdd(@RequestBody MobileOrderVo mobileOrderVo) {
        try {
            return orderService.mobileAdd(mobileOrderVo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("电话预约失败");
        }
    }

    @RequestMapping("/findAll")
    public PageResult findAll(@RequestBody QueryPageBean queryPageBean) {
        return orderSettingService.findAll(queryPageBean);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(int id) {
        try {
            orderService.deleteById(id);
            return Result.success("删除订单成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除订单失败");
        }
    }

    @RequestMapping("/findById")
    public Result findById(int id) {
        try {
            MobileOrderVo mobileOrderVo = orderService.findById(id);
            return Result.success("回显订单成功",mobileOrderVo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("回显订单失败");
        }
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Order order) {
        try {
            orderService.edit(order);
            return new Result(true, "编辑订单成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "编辑订单失败");
        }
    }
    @RequestMapping("/findAllSetmeal")
    public Result findAllSetmeal(){
        List<Setmeal> setmeals = orderSettingService.findAllSetmeal();
        return Result.success("",setmeals);
    }
}
